// CImageAppView.H
//
// Copyright (c) 2002 Symbian Ltd.  All rights reserved.
//

#ifndef CIMAGEHANDLER_H
#define CIMAGEHANDLER_H

#include <e32base.h> 
#include <fbs.h>

// Image converter library API header
#include <ImageConversion.h>
// Bitmap transforms API header
#include <BitmapTransforms.h>
#include "MessageCaller.h"

// Loads, saves and manipulates a bitmap
class CImageHandler : public CActive, public MImageHandlerCallback
{
public:
	void Test();
	void SetCallback(MImageHandlerCallback* aCallback);
	CFbsBitmap* Bitmap();	
    CFbsBitmap* MaskBitmap();
	// Construction
	CImageHandler(RFs& aFs);
	~CImageHandler();

	void CopyBitmap(CFbsBitmap* newBitmap);
	void CopyMaskBitmap(CFbsBitmap* newBitmap);	
	void FastImageInfo(const TDesC& aFileName, TSize& size);	
	void FastImageInfo(TPtrC8* bufptr, TSize& size);
	// Load/save operations
	void LoadFileL(const TDesC& aFileName, int aTaskCode, int aSelectedFrame = 0);
	void LoadBuffer(RFile file, long pos, long size, TInt aSelectedFrame = 0);
	void LoadBuffer(const TPtrC8* bufptr, int aTaskCode, int aSelectedFrame = 0);	

	// Frame information
	const TFrameInfo& FrameInfo() const {return iFrameInfo;}
	// Frame count
	TInt FrameCount() const {return iFrameCount;}
	void SetTaskCode(int aTaskCode);
	
private:	
    void ConstructL();
	void ImageOperationComplete(int aError, int taskcode);
private:
	// Active object interface
	void RunL(); 
	void DoCancel();

private:
	// Callback interface
	MImageHandlerCallback* iCallback;
	// Bitmap
	CFbsBitmap* iBitmap; 
	CFbsBitmap* iMaskBitmap; 	
	// File server handle
	RFs& iFs;
	// Frame information
	TFrameInfo iFrameInfo;
	// Frame count
	TInt iFrameCount;
	// Image file loader
	CImageDecoder* iLoadUtil;
	// Image buffer loader
	CBufferedImageDecoder* iLoadUtil2;
	int iTaskCode;
    };

#endif